/**
	General class to parse XML config files.
	All tags are read as key/value pairs and they are added as all uppercase
	properties of _global. If the optional 3rd parameter to the constructor is true,
	the keys and values are added to the object itself instead of _global.
	
	@implementationNote Private vars are prefixed with $ to hide them from potential conflicts.
	
	@author Chandler McWilliams
	@version 2005-04-14
*/
dynamic class timber.util.Config extends XML
{
	
	private var $url;
	private var $callback;
	private var $local;
	
	
// ===========================================================
// - CONSTRUCTOR
// ===========================================================
/**
	Constructor

	@param newurl Url of the config file
	@param callback Function called when parsing is complete.
	@param local sets if properties are added to this object or to _global, default is false 
*/
	public function Config(newurl:String, callback:Function, local:Boolean) {
		$url = newurl;
		$callback = callback;
		this.ignoreWhite = true;
		$local = (isLocal === true)?true:false;
		this.load($url);
	}
	
	private function onLoad(ok) {
		if (ok) {
			var kids = this.firstChild.childNodes;
			for (var i=0; i<kids.length; i++) {
				this.addProperty(kids[i].nodeName, kids[i].firstChild.nodeValue);
			}
			$callback(true);
		} else {
			$callback(false);
		}
	}
	
	public function addProperty(name, value) {
		// add props if they aren't there
		if (!$local) {
			if (!_global[name.toUpperCase()]) _global[name.toUpperCase()] = value;
		} else {
			if (!this[name.toUpperCase()]) this[name.toUpperCase()] = value;
		}
	}
}